$(document).ready(function(){
	$(".m-content+div>span:last-child").click(function(){
		if($(this).parent().parent().parent().find("textarea").css("display") == 'inline-block'){
			$(this).parent().parent().parent().find("textarea").remove();
		}else{
			$(".m-comment-content+textarea").remove();
			$(this).parent().parent().parent().append("<textarea name=\"\"></textarea>");
		}
		if($(this).parent().parent().parent().find("button").css("display") == 'inline-block'){
			$(this).parent().parent().parent().find("button").remove();
		}else{
			$(".m-comment-content+button").remove();
			$(this).parent().parent().parent().append("<button>评论</button>");
		}
		
	});
	
	$("#newscomment+button").click(function(){
		$.post("AddComment.do",{
			"content":$("#commenttype").val()
			,"parentid":$("#commenttype").attr("data-id")
			,"commenttype":"1"},function(result){
				result = eval('(' + result + ')');
				if(result != undefined && result != null){
					if(result.status != undefined && result.status != null){
						if(result.status == 'ok'){
							alert("评论成功");
							window.location.href="ViewNews.do";
						}else if(result.status == 'error'){
							alert(result.msg);
						}
					}
				}else{
					alert("系统错误");
				}
		});
	});
	
	$(".comment>button").click(function(){
		$.post("AddComment.do",{
			"content":$(this).parent().find("textarea").val()
			,"parentid":$(this).parent().attr("data-id")
			,"commenttype":"2"},
			function(result){
				result = eval('(' + result + ')');
				if(result != undefined && result != null){
					if(result.status != undefined && result.status != null){
						if(result.status == 'ok'){
							alert("评论成功");
							window.location.href="ViewNews.do";
						}else if(result.status == 'error'){
							alert(result.msg);
						}
					}
				}else{
					alert("系统错误");
				}
			}
		);
	});
	
	$("#like").click(function(){
		$.post("Like.do",{
			"commentid":$(this).parent().parent().parent().attr("data-id")
		},function(result){
			result = eval('(' + result + ')');
			if(result != undefined && result != null){
				if(result.status != undefined && result != null){
					if(result.status == 'ok'){
						window.location.href="ViewNews.do";
					}else if(result.status == 'error'){
						alert(result.msg);
					}
				}
			}else{
				alert("系统错误");
			}
		});
	});
	
	$("#dislike").click(function(){
		$.post("DisLike.do",{
			"commentid":$(this).parent().parent().parent().attr("data-id")
		},function(result){
			result = eval('(' + result + ')');
			if(result != undefined && result != null){
				if(result.status != undefined && result != null){
					if(result.status == 'ok'){
						window.location.href="ViewNews.do";
					}else if(result.status == 'error'){
						alert(result.msg);
					}
				}
			}else{
				alert("系统错误");
			}
		});
	});
})